import {
  getNearShopList
} from '../../services/order';

Page({
  data: {
    orderID: 0,
    longitude: '',
    latitude: '',
    shopList: [{
    }, {

    }]
  },
  onLoad(event) {
    my.setNavigationBar({
      title: '附近门店',
    });
    this.setData({ orderId: event.orderId })
    // this.setData({ orderId: event.orderId, longitude: event.longitude, latitude: event.latitude })
    this.getNearShopList()
  },

  makePhoneCall(event) {
    my.makePhoneCall({ number: event.target.dataset.phone });
  },
  tolocation(event) {
    let shopInfo = this.data.shopList[event.target.dataset.index]
    my.openLocation({
      longitude: shopInfo.longitude,
      latitude: shopInfo.latitude,
      name: shopInfo.shopName,
      address: shopInfo.detail
    })
  },
  getNearShopList() {
    let param = {};
    if (this.data.orderId) {
      param.orderId = this.data.orderId
    }
    let that = this
    my.getLocation({
      success(res) {
        that.setData({
          longitude: res.longitude,
          latitude: res.latitude
        })
      },
      fail() {
      },
      complete() {
        if (that.data.longitude) {
          param.longitude = that.data.longitude
        }
        if (that.data.latitude) {
          param.latitude = that.data.latitude
        }
        getNearShopList(param).then(res => {
          if (res.code == "000000") {
            that.setData({ shopList: res.data })
          }
        })
      }
    })


  }
});
